<template>
	<view class="all-main">
		<view class="main">
			<u-sticky>
				<view class="top">
					<u-subsection :list="typeList" mode="subsection" fontSize="15" :current="current"
						@change="sectionChange"></u-subsection>
				</view>
			</u-sticky>
			<view v-if="lists.length > 0" class="lists">
				<view v-for="(item, index) in lists" :key="index" class="items" @click="edits(item)">
					<view class="tags">
						<text>商户入网</text>
					</view>
					<view class="title">
						<text>{{item.busName}}</text>
					</view>
					<view class="item-text">
						<text>商户编号：</text>
						<text>{{item.custId == '' ? '--' : item.custId}}</text>
					</view>
					<view class="item-text">
						<text>商户简称：</text>
						<text>{{item.refName == '' ? '--' : item.refName}}</text>
					</view>
					<view class="item-text">
						<text>申请时间：</text>
						<text>{{item.submit_time}}</text>
					</view>
					<view v-if="item.check_state == 4" class="item-error">
						<text>拒绝原因：</text>
						<text>{{item.error_msg}}</text>
					</view>
				</view>
			</view>
			<u-empty v-else mode="list" icon="/static/Empty/data_null.png"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				typeList: ['审核中', '审核驳回'],
				current: 0,
				lists: [],
				page: 1,
				bottom: true,
			}
		},
		onLoad() {
			this.loadData()
		},
		//上拉加载
		onReachBottom() {
			if (this.bottom == true) {
				this.page += 1
				this.loadData()
			}
		},
		methods: {
			// 切换类型
			sectionChange(index) {
				this.current = index
				this.lists = []
				this.page = 1
				this.bottom = true
				this.loadData()
			},
			// 加载数据
			async loadData() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getMerchantCheckList',
					data: {
						page: this.page,
						type: this.current + 1
					}
				});
				uni.hideLoading()
				if (res.code == 200) {
					if (res.data.data !== undefined && res.data.data !== null && res.data.data.length >
						0) {
						if (this.page == 1) {
							this.lists = res.data.data
						} else {
							this.lists = [...this.lists, ...res.data.data]
						}
					} else {
						this.bottom = false
					}
				}
			},
			// 修改
			edits(item) {
				if (item.check_state == 4) {
					uni.navigateTo({
						url: '/pages/index/guotong/index?id=' + item.id
					})
				}
			},
		}
	}
</script>

<style lang="scss">
	.all-main {
		.main {
			.top {
				padding: 30rpx;
				background-color: #F2F6FC;
			}

			.lists {
				margin: 0 30rpx 30rpx 30rpx;

				.items {
					background-color: #ffffff;
					border-radius: 16rpx;
					padding: 30rpx;
					margin-bottom: 30rpx;
					position: relative;

					.tags {
						position: absolute;
						top: 0;
						right: 0;
						background-color: #dbf1e1;
						color: #19be6b;
						font-size: 24rpx;
						padding: 10rpx;
						border-top-right-radius: 16rpx;
						border-bottom-left-radius: 16rpx;
					}

					.title {
						font-weight: bold;
					}

					.item-text {
						margin-top: 10rpx;
						color: #909399;
					}

					.item-error {
						margin-top: 10rpx;
						color: #fa3534;
					}
				}
			}
		}
	}
</style>